package com.boc.langxiang.ui.activity.shop;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.boc.langxiang.R;
import com.boc.langxiang.net.H5Url;
import com.boc.langxiang.ui.activity.BaseToolBarActivity;
import com.boc.langxiang.ui.view.webview.ObservableWebView;
import com.boc.langxiang.util.StringUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 产品详情--空间设计师
 */
public class ProductDetail2Activity extends BaseToolBarActivity {
    @BindView(R.id.webView)
    ObservableWebView mWebView;

    private String webUrl;
    private String mId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_detail2);
        ButterKnife.bind(this);

        Intent intent = getIntent();
        mId = intent.getStringExtra("id");
        if (StringUtil.isEmpty(mId)) {
            finish();
            return;
        }

        initWebViews();
    }

    private void initWebViews() {
        mWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                Log.d("url", url);
                if (url.equals(webUrl)) {
                    view.loadUrl(url);
                }
                return true;
            }
        });

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setBuiltInZoomControls(false);
        webSettings.setUseWideViewPort(true);
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        webSettings.setLoadsImagesAutomatically(true);
//        mWebView.setScrollViewCallbacks(this);

        webUrl = H5Url.PRODUCT_DETAIL + mId;
        mWebView.loadUrl(webUrl);
    }


}
